package com.items;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.endwork.R;

import java.util.List;

public class MyAdapter extends BaseAdapter {
    private List<person> data;
    private Context context;
    private LayoutInflater inflater;
    public MyAdapter(Context context, List<person> data){
        this.context=context;
        this.data=data;
        this.inflater=LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return data.size();//数据列表大小
    }

    @Override
    public Object getItem(int i) {
        return data.get(i);//指定数据
    }

    @Override
    public long getItemId(int i) {
        return i;//指定位置id
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.cell, parent, false);
        }

        person dataItem=this.data.get(position);
        TextView leftText=convertView.findViewById(R.id.leftTextView);
        TextView righText=convertView.findViewById(R.id.rightTextView);
        leftText.setText(dataItem.getName());
        righText.setText(dataItem.getPhone_1());
        return convertView;
    }
}
